package com.teach.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teach.mapper.CourseMapper;
import com.teach.mapper.ScoreMapper;
import com.teach.pojo.Course;
import com.teach.pojo.RespBean;
import com.teach.pojo.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService{
    @Autowired
    private ScoreMapper scoreMapper;
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public RespBean getScores(Long userId) {
        List<Score> scores = scoreMapper.selectList(new QueryWrapper<Score>().eq("user_id", userId));
        scores.forEach(item->{
            item.setCourseName(courseMapper.selectOne(new QueryWrapper<Course>().eq("id",item.getId())).getCourseName());
        });

        return RespBean.success(scores);
    }

    @Override
    public void updateScore(Long userId, Long courseId, Integer num) {
        scoreMapper.updateScore(userId, courseId, num);
    }
}
